package com.example.demo.ThreadPool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 创建一个线程池,可控制线程最大并发数超过的线程数,超出的线程会在队列中等待
 */
public class MyDemo01 {

    public static void main(String[] args) {
        //01创建可缓存的线程池,可重复利用
        ExecutorService executorService = Executors.newCachedThreadPool();
        //创建缓存的线城市,可重利用
        for (int i = 0; i <10; i++) {
            int temp = i;
            executorService.execute(new Runnable() {
                @Override
                public void run() {
                    System.out.println("ThreadName"+Thread.currentThread().getName());
                }
            });
        }
    }
}
